package de.hatraco.funderberg.blackjack.views;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.SwingConstants;

import de.hatraco.funderberg.blackjack.data.DataMISC;
import de.hatraco.funderberg.blackjack.data.GraphicsBlackJack;

public class InfoDialog extends JDialog {
	
	//Singleton Pattern: Stellt sicher, dass nur eine Instanz von InfoDialog existiert
	private static InfoDialog instance = new InfoDialog();

	public static InfoDialog getInstance() {
		if(instance == null) {
			instance = new InfoDialog();
		}
		return instance;
	}
	
	private JLabel bg_info;
	private JLabel nextplayer;
	private JLabel double1;
	private JLabel double2;
	private JLabel double3;
	
	private JButton b_yes;
	private JButton b_no;
	
	//private String link = DataMISC.LINKIMG;
	
	private GraphicsBlackJack img;
	
	private InfoDialog() {
		
		//Instanziert GraphicsBlackJack (für die Bilder)
		this.img = GraphicsBlackJack.getInstance();
		
		//Legt die Größe des Fensters fest
		this.setSize(400,300);
		//Legt fest, dass die Größe nicht verändert werden kann
		this.setResizable(false);
		//Legt fest, dass das Fenster nicht über das "X" rechts oben geschlossen werden kann
		this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
		//Gibt dem Fenster ein BorderLayout
		this.setLayout(new BorderLayout());
		//Legt den Hintergrund fest
        bg_info = new JLabel(img.getBgdialogdef());
        //Fügt den Hintergrund hinzu
        this.add(bg_info);
        //Gibt dem Hintergrund ein "leeres" Layout
        bg_info.setLayout(null);
        
        //Instanziert, Modifiziert und Positioniert die Elemente
        //JLabels
        nextplayer = new JLabel();
        nextplayer.setFont(DataMISC.ARIAL_BOLD20);
        nextplayer.setForeground(Color.WHITE);
        nextplayer.setBounds(0, 120, 400, 25);
        nextplayer.setHorizontalAlignment(SwingConstants.CENTER);
        nextplayer.setVerticalAlignment(SwingConstants.CENTER);
        nextplayer.setVisible(false);
        
        double1 = new JLabel("Do you really want to double down?");
        double1.setFont(DataMISC.ARIAL_BOLD20);
        double1.setForeground(Color.WHITE);
        double1.setBounds(0, 40, 400, 25);
        double1.setHorizontalAlignment(SwingConstants.CENTER);
        double1.setVisible(false);
        
        double2 = new JLabel("You will receive exactly");
        double2.setFont(DataMISC.ARIAL_BOLD20);
        double2.setForeground(Color.WHITE);
        double2.setBounds(0, 90, 400, 25);
        double2.setHorizontalAlignment(SwingConstants.CENTER);
        double2.setVisible(false);
        
        double3 = new JLabel("ONE more card!");
        double3.setFont(DataMISC.ARIAL_BOLD20);
        double3.setForeground(Color.WHITE);
        double3.setBounds(0, 125, 400, 25);
        double3.setHorizontalAlignment(SwingConstants.CENTER);
        double3.setVisible(false);
        
        //Buttons
        b_yes = new JButton(img.getBtyes());
        b_yes.setBounds(80, 185, 80, 40);
        b_yes.setVisible(false);
        b_no = new JButton(img.getBtno());
        b_no.setBounds(240, 185, 80, 40);
        b_no.setVisible(false);
        
        //Fügt die Elemente dem Hintergrund hinzu
        bg_info.add(nextplayer);
        bg_info.add(double1);
        bg_info.add(double2);
        bg_info.add(double3);
        bg_info.add(b_yes);
        bg_info.add(b_no);
	}
	
	//Definiert Listener für die Buttons
	public void setInfoListener(ActionListener ae) {
		this.b_yes.addActionListener(ae);
		this.b_no.addActionListener(ae);
	}
	
	public JLabel getNextplayer() {
		return nextplayer;
	}

	public void setNextplayer(JLabel nextplayer) {
		this.nextplayer = nextplayer;
	}

	public JLabel getDouble1() {
		return double1;
	}

	public void setDouble1(JLabel double1) {
		this.double1 = double1;
	}

	public JLabel getDouble2() {
		return double2;
	}

	public void setDouble2(JLabel double2) {
		this.double2 = double2;
	}
	
	public JLabel getDouble3() {
		return double3;
	}

	public void setDouble3(JLabel double3) {
		this.double3 = double3;
	}

	public JButton getB_yes() {
		return b_yes;
	}

	public void setB_yes(JButton b_yes) {
		this.b_yes = b_yes;
	}

	public JButton getB_no() {
		return b_no;
	}

	public void setB_no(JButton b_no) {
		this.b_no = b_no;
	}
}
